<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2007 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$

class CommonAction extends Action {
	public $u_domain;
	public $Member;//会员对象
    public function _initialize(){	
		$this->Member = D('Member');
		$u_domain = substr($_SERVER['HTTP_HOST'], 0, -7);
		if(empty($u_domain)){$u_domain = 'www';}
		$this->u_domain = $u_domain;
		//extract($_GET);
		//header("Content-Type:text/html; charset=utf-8");
		$_REQUEST['ActionName'] = $this->getActionName();
    }
	#获取导航列表
	public function getNavigator(){
		$Navigator=D('Navigator')->getNavigator();
		$this->assign('Navigator',$Navigator);
		return $Navigator;
	}
	#获取用户的搜索引擎,如果已经登录，或者用户设置，再使用默认设置
	public function getSearchEngine(){
		$Member = D('Member');
		$SearchEngines = $Member->getSearchEngine($this->u_domain);
		$this->assign('SearchEngines',$SearchEngines);
		//print_r($SearchEngines);
		return $SearchEngines;
	}
	#获取会员登录状态的html
	public function loginHtml(){
		if($this->Member->isLoggedin()){
			$this->assign('islogin',true);
		}
		$this->display('Index:loginHtml');
	}
	#顶部菜单
	public function topMenu(){
		if($this->Member->isLoggedin() and $this->u_domain == session('u_domain')){//如果已经登录，并且访问的是自己的主页
			$this->assign('is_my',true);
		}
		$this->display('Index:topMenu');
	}
    /**
     +----------------------------------------------------------
     * 文件上传功能，支持多文件上传、保存数据库、自动缩略图
     +----------------------------------------------------------
     * @access protected
     +----------------------------------------------------------
     * @return void
     * @param int $shui_img 是否要水印
     * @param int $yuanImg 是否删除原图
     +----------------------------------------------------------
     * @throws ThinkExecption
     +----------------------------------------------------------
     */
/*    protected function _upload($shui_img=1,$yuanImg=0)
    {
        import("ORG.Net.UploadFile");
        $upload = new UploadFile();
        //设置上传文件大小 字节
        $upload->maxSize = 3292200;
        //设置上传文件类型
        $accessories = D("Accessories");
        $accessories->create();
        $accessoriesList = $accessories->find();

        if(count($accessoriesList)>0){
            $upload->allowExts = explode(',', $accessoriesList["file_type"]);
        }else{
            $upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
        }
        
        //设置附件上传目录
        $imp_path = date("Ym")."/";
        $upload->savePath = '/Public/Uploads/'.$imp_path;
        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb = true;
        // 设置引用图片类库包路径
        $upload->imageClassPath = 'ORG.Util.Image';
        //设置需要生成缩略图的文件后缀
        $upload->thumbPrefix = 's_';  //生成2张缩略图
        //设置缩略图最大宽度
        if(!empty($accessoriesList["thum_width"])){
            $upload->thumbMaxWidth = $accessoriesList["thum_width"];
        }else{
            $upload->thumbMaxWidth = '200';
        }
        
        //设置缩略图最大高度
        if(!empty($accessoriesList["thum_height"])){
            $upload->thumbMaxHeight = $accessoriesList["thum_height"];
        }else{
            $upload->thumbMaxHeight = '300';
        }

        //设置上传文件规则
        $upload->saveRule = uniqid;
        //删除原图
        if($shui_img){
            if($yuanImg !=1){ //删除原图
                $upload->thumbRemoveOrigin = true;
                
            }
        }else{
            $upload->thumbRemoveOrigin = false;
        }
        
        if (!$upload->upload()) {
            //捕获上传异常
            $this->error($upload->getErrorMsg());
        } else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            
            //是否调用水印图
            if($shui_img){ //是要
                $Figure = D("Figure");
                $Figure->create();
                $img_arr = $Figure->where("figure_water='1'")->field("img_path")->find();
                for($i=0;$i<count($uploadList);$i++){
                    if(!empty($img_arr["img_path"])){
                        import("ORG.Util.Image");
                        //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
                        $docuRoot = $_SERVER['DOCUMENT_ROOT'];
                        Image::water($docuRoot.$uploadList[$i]['savepath'].'m_'.$uploadList[$i]['savename'],$docuRoot.$img_arr["img_path"]);
                        $imgArr[$i][] = $uploadList[$i]['savepath'].'m_'.$uploadList[$i]['savename'];
                        
                        Image::water($docuRoot.$uploadList[$i]['savepath'].'s_'.$uploadList[$i]['savename'],$docuRoot.$img_arr["img_path"]);
                        $imgArr[$i][] = $uploadList[$i]['savepath'].'s_'.$uploadList[$i]['savename'];
                        
                        $imgArr[$i][] = $uploadList[$i]['savepath'].$uploadList[$i]['savename']; //原图
                    }else{
                        $imgArr[$i][] = $uploadList[$i]['savepath'].'m_'.$uploadList[$i]['savename'];
                        $imgArr[$i][] = $uploadList[$i]['savepath'].'s_'.$uploadList[$i]['savename'];
                        
                        $imgArr[$i][] = $uploadList[$i]['savepath'].$uploadList[$i]['savename']; //原图
                    }
                }
            }else{
                $imp_path = $uploadList[0]['savepath'].$uploadList[0]['savename'];
            }
        }
        if(!empty($imgArr)){
            return $imgArr;
        }else{
            return $imp_path;
        }
        
    }*/
    
}
?>